home *** CD-ROM | disk | FTP | other *** search
/ DOpus Plus / DOpus Plus.iso / Tutorial / C Guide / RndPic_module / modinit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-20  |  4.3 KB  |  159 lines

  1. /****************************************************************************
  2.  
  3.  modinit.c - standard initialisation for Opus 5 modules
  4.  
  5.  ****************************************************************************/
  6.  
  7. #ifndef _DOPUS_MODULE_DEF
  8. #define _DOPUS_MODULE_DEF
  9. #include <dopus/modules.h>
  10. #endif
  11.  
  12. #ifndef CLIB_EXEC_PROTOS_H
  13. #include <clib/exec_protos.h>
  14. #include <pragmas/exec_pragmas.h>
  15. #endif
  16.  
  17. #ifndef EXEC_MEMORY_H
  18. #include <exec/memory.h>
  19. #endif
  20.  
  21. #ifndef CLIB_LOCALE_PROTOS_H
  22. #include <clib/locale_protos.h>
  23. #include <pragmas/locale_pragmas.h>
  24. #endif
  25.  
  26. /********************************************************************/
  27.  
  28. // SAS/C stuff
  29. int  __saveds __UserLibInit(void);
  30. void __saveds __UserLibCleanup(void);
  31.  
  32. struct Library *DOSBase;
  33. struct Library *AslBase;
  34. struct Library *DOpusBase;
  35. struct Library *LocaleBase;
  36. struct Library *UtilityBase;
  37. struct Library *GadToolsBase;
  38. struct Library *IntuitionBase;
  39. struct Library *RexxSysBase; 
  40.  
  41. APTR mempool; // a globally mempool for the module
  42.  
  43. // Locale pointer
  44. struct DOpusLocale *locale;
  45.  
  46.  
  47. // Library initialisation code
  48. __saveds __UserLibInit()
  49. {
  50.         // Initialise pointers
  51.         AslBase = 0;
  52.         DOpusBase=0;
  53.         LocaleBase=0;
  54.         UtilityBase=0;
  55.         GadToolsBase = 0;
  56.         IntuitionBase = 0;
  57.         RexxSysBase=0; 
  58.         
  59.         locale=0;
  60.         mempool = NULL;
  61.                        
  62.         // Get DOS library (can't really fail)
  63.         DOSBase=OpenLibrary("dos.library",0);
  64.  
  65.         // Open other libraries we need
  66.         if( !(AslBase = OpenLibrary("asl.library", 37)) ||
  67.             !(DOpusBase=OpenLibrary("dopus5.library",55)) ||
  68.             !(UtilityBase=OpenLibrary("utility.library",37)) ||
  69.             !(GadToolsBase = OpenLibrary( "gadtools.library", 37)) ||
  70.             !(IntuitionBase = OpenLibrary( "intuition.library", 37)) ||
  71.             !(RexxSysBase=OpenLibrary("rexxsyslib.library",0)) )
  72.             return 1;
  73.         
  74.         if( !(mempool = NewMemHandle(4096, 3072, MEMF_CLEAR|MEMF_PUBLIC)) ||
  75.             !(locale = AllocMemH(mempool, sizeof(struct DOpusLocale))) )
  76.              {
  77.                 return 1;
  78.              } 
  79.         
  80.         
  81.         init_locale_data(locale);
  82.  
  83.         // Open locale library
  84.         if (LocaleBase=OpenLibrary("locale.library",38))
  85.         {
  86.                 // Store library pointer
  87.                 locale->li_LocaleBase=LocaleBase;
  88.  
  89.                 // Open catalog if name supplied
  90.                 if (module_info.locale_name)
  91.                 {
  92.                         struct TagItem tags[2];
  93.  
  94.                         // If MODULEF_CATALOG_VERSION is set, we do version checking
  95.                         tags[0].ti_Tag=(module_info.flags&MODULEF_CATALOG_VERSION)?OC_Version:TAG_IGNORE;
  96.                         tags[0].ti_Data=module_info.ver;
  97.                         tags[1].ti_Tag=TAG_END;
  98.  
  99.                         // Open catalog
  100.                         locale->li_Catalog=OpenCatalogA(NULL,module_info.locale_name,tags);
  101.                 }
  102.  
  103.                 // Get default lolale
  104.                 locale->li_Locale=OpenLocale(0);
  105.         }
  106.         
  107.       return NULL; // Succeeded
  108. }
  109.  
  110.  
  111. // Clean up
  112. void __saveds __UserLibCleanup()
  113. {
  114.         
  115.         if( mempool )
  116.           {
  117.              if( locale )
  118.                {
  119.                   if( LocaleBase )
  120.                     {
  121.                        CloseLocale(locale->li_Locale);
  122.                        CloseCatalog(locale->li_Catalog);
  123.                        CloseLibrary(LocaleBase);
  124.                     }
  125.                   FreeMemH(locale);
  126.                }
  127.              
  128.              FreeMemHandle( mempool );
  129.           }
  130.         
  131.         // Close libraries
  132.         CloseLibrary( AslBase );
  133.         CloseLibrary(DOpusBase);
  134.         CloseLibrary(UtilityBase);
  135.         CloseLibrary(RexxSysBase);
  136.         CloseLibrary( GadToolsBase );
  137.         CloseLibrary( IntuitionBase );
  138.         CloseLibrary(DOSBase);
  139. }
  140.  
  141.  
  142. // This routine is called by Opus to find out what the module does
  143. ModuleInfo *__asm __saveds L_Module_Identify(register __d0 int num)
  144. {
  145.         // Return module information
  146.         if (num==-1) return &module_info;
  147.  
  148.         // Valid function number?
  149.         if (num>module_info.function_count || !(module_info.function[num].desc)) return 0;
  150.  
  151.         // Return function description
  152.         return (ModuleInfo *)DOpusGetString(locale,module_info.function[num].desc);
  153. }
  154.  
  155. /********************************************************************/
  156.  
  157.  
  158.  
  159.